package s47.dqj.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import s47.dqj.bean.DoctorMethod;
/**
 * 21.处方名称表
 * @author Administrator
 *
 */
@Repository("doctorMethodDaoImpl")
public class DoctorMethodDaoImpl extends HibernateDaoSupport implements DoctorMethodDaoInf {
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#setSupperSessionFactory(org.hibernate.SessionFactory)
	 */
	@Override
	@Resource(name="sessionFactory")
	public void setSupperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#findAllByCondition(java.lang.String, java.lang.Integer)
	 */
	@Override
	public List<DoctorMethod> findAllByCondition(String hql,Integer pageNum){
		Query query=getSession().createQuery(hql);
		query.setFirstResult((Integer.valueOf(pageNum)-1)*15);
		query.setMaxResults(15);
		return query.list();
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#selectPageTotal(java.lang.String)
	 */
	@Override
	public List<Integer> selectPageTotal(String tempHQL){
		List<Integer> pageTotal=new ArrayList<Integer>();
		int p;
		Long temp;
		String hql="select Count(*) from DoctorMethod as dm"+tempHQL;
		Query query=getSession().createQuery(hql);
		temp=(Long)query.uniqueResult();
		
		if(temp%15!=0)
			p=(int)(temp/15+1);
		else
			p=(int)(temp/15);
		for(int n=0;n<p;n++){
			pageTotal.add(n+1);
		}
		return pageTotal;
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#save(s47.dqj.bean.DoctorMethod)
	 */
	@Override
	public void save(DoctorMethod doctorMethod){
		getHibernateTemplate().save(doctorMethod);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#update(s47.dqj.bean.DoctorMethod)
	 */
	@Override
	public void update(DoctorMethod doctorMethod){
		getHibernateTemplate().update(doctorMethod);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#delete(s47.dqj.bean.DoctorMethod)
	 */
	@Override
	public void delete(DoctorMethod doctorMethod){
		getHibernateTemplate().delete(doctorMethod);
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.DoctorMethodDaoInf#findObject(s47.dqj.bean.DoctorMethod)
	 */
	@Override
	public DoctorMethod findObject(DoctorMethod doctorMethod){
		return getHibernateTemplate().get(DoctorMethod.class, doctorMethod.getDmid());
	}
}
